package com.mujin.keji.collectionsystem.module.outboundtask.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.VisithouseDto;

import java.util.List;


/**
 * 选择外访房屋适配器
 *
 * @author weishixiong
 * @Time 2018-05-12
 */
public class InnerdecorationseAdapter extends RecyclerView.Adapter<InnerdecorationseAdapter.ViewHolder> {
    private int[] photos = new int[]{R.drawable.shape_input_to_visit, R.drawable.shape_button_select_bg};
    private String[] colors = new String[]{"#999999", "#FFFFFF"};
    private Context mContext;
    private List<VisithouseDto> datas;
    private InnerdecorationsSelectListener listener;

    public  interface InnerdecorationsSelectListener {
        void onSelectInnerdecorations(int position);
    }

    public InnerdecorationseAdapter(Context context, List<VisithouseDto> datas, InnerdecorationsSelectListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_to_visit, null, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvName.setText(datas.get(position).getContent());
        if (datas.get(position).isSelect()) {
            holder.tvName.setTextColor(Color.parseColor(colors[1]));
            holder.tvName.setBackgroundResource(photos[1]);
        } else {
            holder.tvName.setTextColor(Color.parseColor(colors[0]));
            holder.tvName.setBackgroundResource(photos[0]);
        }
        holder.tvName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onSelectInnerdecorations(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private TextView tvName;

        public ViewHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_name);

        }

        @Override
        public void onClick(View v) {

        }
    }
}
